﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JustCodeTest
{
    enum Specialty
    {
        KST,
        KTT,
        KN,
        SI
    }

    enum University
    {
        SU,
        TU
    }

    enum Faculty
    {
        FKSU,
        FMI
    }

    class Student : ICloneable, IComparable<Student>
    {
        public string FirstName { get; set; }
        public string MiddleName { get; private set; }
        public string LastName { get; private set; }
        public string SSN { get; private set; }
        public string PermanentAddress { get; private set; }
        public string Phone { get; private set; }
        public string Email { get; private set; }
        public byte Course { get; private set; }
        public University University { get; private set; }
        public Faculty Faculty { get; private set; }
        public Specialty Specialty { get; private set; }

        public Student(string fname, string mname, string lname, string ssn, string paddress, string phone,
            string email, byte course, University university, Faculty faculty, Specialty specialty)
        {
            this.FirstName = fname;
            this.MiddleName = mname;
            this.LastName = lname;
            this.SSN = ssn;
            this.PermanentAddress = paddress;
            this.Phone = phone;
            this.Email = email;
            this.Course = course;
            this.University = university;
            this.Faculty = faculty;
            this.Specialty = specialty;
        }

        public override bool Equals(object obj)
        {
            Student student = obj as Student;
            if (student == null)
            {
                return false;
            }
            if (Object.Equals(this.FirstName, student.FirstName) &&
                Object.Equals(this.MiddleName, student.MiddleName) &&
                Object.Equals(this.LastName, student.LastName) &&
                Object.Equals(this.SSN, student.SSN) &&
                Object.Equals(this.PermanentAddress, student.PermanentAddress) &&
                Object.Equals(this.Phone, student.Phone) &&
                Object.Equals(this.Email, student.Email) &&
                Object.Equals(this.Course, student.Course) &&
                Object.Equals(this.University, student.University) &&
                Object.Equals(this.Faculty, student.Faculty) &&
                Object.Equals(this.Specialty, student.Specialty))
            {
                return true;
            }
            return false;
        }

        public override string ToString()
        {
            return ("Name: " + this.FirstName + " " + this.MiddleName + " " + this.LastName + "\n" +
                "SSN: " + this.SSN + "\nAddress: " + this.PermanentAddress + "\nPhone: " + this.Phone +
                "\ne-mail: " + this.Email + "\nCourse: " + this.Course + "\nUniversity: " +
                this.University + "\nFaculty: " + this.Faculty + "\nSpecialty: " + this.Specialty);
        }

        public override int GetHashCode()
        {
            return (this.FirstName.GetHashCode() ^ this.MiddleName.GetHashCode() ^ 
                this.LastName.GetHashCode() ^ this.SSN.GetHashCode() ^ this.PermanentAddress.GetHashCode() ^
                this.Phone.GetHashCode() ^ this.Email.GetHashCode() ^ this.Course ^ 
                this.University.GetHashCode() ^ this.Faculty.GetHashCode() ^ this.Specialty.GetHashCode());
        }

        public static bool operator ==(Student st1, Student st2)
        {
            if (Student.ReferenceEquals(st1, null) && Student.ReferenceEquals(st2, null))
            {
                return true;
            }
            if(Student.ReferenceEquals(st1, null))
            {
                return false;
            }
            if (Student.ReferenceEquals(st2, null))
            {
                return false;
            }
            if (st1.Equals(st2))
            {
                return true;
            }
            return false;
        }

        public static bool operator !=(Student st1, Student st2)
        {
            return !(st1 == st2);
        }
        
        object ICloneable.Clone()
        {
            return this.Clone();
        }

        public Student Clone()
        {
            return (new Student(this.FirstName, this.MiddleName, this.LastName, this.SSN, this.PermanentAddress,
                this.Phone, this.Email, this.Course, this.University, this.Faculty, this.Specialty));
        }

        public int CompareTo(Student other)
        {
            int compareValue = this.FirstName.CompareTo(other.FirstName);
            if (compareValue != 0)
            {
                return compareValue;
            }
            else
            {
                compareValue = this.MiddleName.CompareTo(other.MiddleName);
                if (compareValue != 0)
                {
                    return compareValue;
                }
                else
                {
                    compareValue = this.LastName.CompareTo(other.LastName);
                    if (compareValue != 0)
                    {
                        return compareValue;
                    }
                    else
                    {
                        compareValue = this.SSN.CompareTo(other.SSN);
                        if (compareValue != 0)
                        {
                            return compareValue;
                        }
                        else
                        {
                            return 0;
                        }
                    }
                }
            }
        }
    }
}
